<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <!--<meta name="viewport" content="width=device-width, initial-scale=1.0 user-scalable=no">-->
    <meta name="format-detection" content="telephone=no" />
    <title>沟通中</title>
    <link rel="stylesheet" type="text/css" href="/newcj/css/themes.css?v=2017129">
    <link rel="stylesheet" type="text/css" href="/newcj/fonts/iconfont.css?v=2016070717">

    <link rel="stylesheet" type="text/css" href="/newcj/css/h5app.css">
    <link rel="stylesheet" type="text/css" href="/newcj/fonts/iconfont.css?v=2016070717">
    <link rel="stylesheet" type="text/css" href="/newcj/css/chat_list.css">
    <script src="/newcj/js/jquery.min.js"></script>
    <script src="/newcj/js/dist/flexible/flexible_css.debug.js"></script>
    <script src="/newcj/js/dist/flexible/flexible.debug.js"></script>

</head>
<body>
<div class='fui-page-group'>
    <div class="fui-statusbar"></div>
    <div class='fui-page chat-page'>
        <div class="fui-header">
            <div class="title">消息列表</div>
            <div class="fui-header-right"></div>
        </div>

        <div class="fui-content navbar chat-fui-content" style="padding-bottom: 2rem;">



        </div>
    </div>
</div>
</body>
<script>


    $(function () {
        var fromid ={$fromid};

        console.log("toformid:",fromid);

        var ws = new WebSocket("ws://tp.luyir.cn:8282");

        ws.onmessage=function(e){
            var message = eval("("+ e.data+")");

            switch (message.type){
                case  "init":
                    var bild = '{"type":"bind","fromid":"'+fromid+'"}';
                    ws.send(bild);

                    list();
                    return;
                case "text":
                    $(".chat-fui-content").html("");
                    //当socket 服务器给我们发送消息的时候,就要去更新聊天列表
                    list();
                    return;
                case "say_img":
                    $(".chat-fui-content").html("");
                    list();
                    return;

            }
        }

        function list(){
            let url = "/admin/chat/index/getChitchatList";
            $.post(url,{fromid} , function (res) {
                if(res.code == 1){
                    let list = res.data.list;
                    let html = '';
                    $.each(list,function (index,item) {
                        html +=  `<div class="chat-list flex"><div class="chat-img" style="background-image: url(`+item.head_url+`)">`;
                        if(item.countNoRead){
                            html += `<span class="badge" style="top: -0.1rem;left: 80%;">`+item.countNoRead+`</span>`;
                        }
                        html+=`</div>
                                <div class="chat-info">
                                        <p class="chat-merch flex">
                                            <span class="title t-28">`+item.username+`</span>
                                            <span class="time">2017-12-14</span>
                                        </p>
                                        <p class="chat-text singleflow-ellipsis">`+item.last_message+`</p>
                                    </div>
                                </div>`;
                    })

                    $('.chat-fui-content').append(html);
                }
            }, 'json');
        }



        /**
         *根据时间戳格式化为日期形式
         */
        function mydate(nS){

            return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
        }

        function redi(url){
            window.location.href=url;
        }
    })




</script>

</html>
